#include "MainWindow.h"
#include "GLWidget.h"
#include <QHBoxLayout>
#include <QTabWidget>


MainWindow* MainWindow::m_instance = 0;


MainWindow::MainWindow(void)
{
	setupUi();
}


MainWindow::~MainWindow(void)
{

}


MainWindow* MainWindow::getInstance() {
	if (m_instance == 0)
		m_instance = new MainWindow();
	return m_instance;
}


void MainWindow::setupUi() {

	this->resize(WINDOW_WIDTH0, WINDOW_HEIGHT0);
	
	QWidget *widget = new QWidget(this);
	QHBoxLayout *layout = new QHBoxLayout(widget);
	layout->setSpacing(6);
    layout->setMargin(5);

	// opengl widget
	m_glWidget = new GLWidget(widget);
	QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    sizePolicy.setHorizontalStretch(0);
    sizePolicy.setVerticalStretch(0);
    sizePolicy.setHeightForWidth(m_glWidget->sizePolicy().hasHeightForWidth());
    m_glWidget->setSizePolicy(sizePolicy);
	m_glWidget->setMinimumSize(QSize(512, 512));

	// tabs in the right side
	m_menuTabs = new QTabWidget(widget);
	m_menuTabs->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
	m_menuTabs->setMaximumWidth(256);
	
	layout->addWidget(m_glWidget);
	layout->addWidget(m_menuTabs);

	widget->setLayout(layout);
	this->setCentralWidget(widget);


	this->resize(580, 580);
}


void MainWindow::addMenuTab(QString name, QWidget* tab) {
	tab->setParent(m_menuTabs);
	m_menuTabs->addTab(tab, name);
}


GLWidget* MainWindow::getGLWidget() {
	return m_glWidget;
}